import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
import { RolesGuard } from '@wwjCommon/security/guards/roles.guard';
import { Roles } from '@wwjCommon/security/decorators/roles.decorator';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request
import { VerifierService } from '../../services/admin/verifier.service';

/**
 * VerifierController
 * 对应 PHP: Verifier Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('verify')
@Controller('adminapi/verify')
export class VerifierController {
  constructor(private readonly verifierService: VerifierService) {}

  /**
   * 核销人员
   * 路由: GET verifier
   * PHP路由: Route::get('verifier', 'verify.Verifier/lists')
   */
  @Get('verifier')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '核销人员' })
  async lists(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: lists

      return await this.verifierService.getPage();
    } catch (error) {
      throw new BusinessException('lists操作失败', error);
    }
  }

  /**
   * 核销人员
   * 路由: GET verifier/select
   * PHP路由: Route::get('verifier/select', 'verify.Verifier/select')
   */
  @Get('verifier/select')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '核销人员' })
  async select(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: select

      return await this.verifierService.getList();
    } catch (error) {
      throw new BusinessException('select操作失败', error);
    }
  }

  /**
   * 核销人员
   * 路由: GET verifier/:id
   * PHP路由: Route::get('verifier/:id', 'verify.Verifier/detail')
   */
  @Get('verifier/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '核销人员' })
  async detail(@Param('id') id: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: detail

      return await this.verifierService.getDetail(id);
    } catch (error) {
      throw new BusinessException('detail操作失败', error);
    }
  }

  /**
   * 核销人员
   * 路由: POST verifier
   * PHP路由: Route::post('verifier', 'verify.Verifier/add')
   */
  @Post('verifier')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '核销人员' })
  async add(@Body() data: AddDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: add

      return await this.verifierService.add(data);
    } catch (error) {
      throw new BusinessException('add操作失败', error);
    }
  }

  /**
   * 核销人员
   * 路由: POST verifier/:id
   * PHP路由: Route::post('verifier/:id', 'verify.Verifier/edit')
   */
  @Post('verifier/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '核销人员' })
  async edit(
    @Param('id') id: string,
    @Body() data: EditDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: edit

      return await this.verifierService.edit(id, data);
    } catch (error) {
      throw new BusinessException('edit操作失败', error);
    }
  }

  /**
   * 核销人员
   * 路由: DELETE verifier/:id
   * PHP路由: Route::delete('verifier/:id', 'verify.Verifier/del')
   */
  @Delete('verifier/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '核销人员' })
  async del(@Param('id') id: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: del

      return await this.verifierService.del(id);
    } catch (error) {
      throw new BusinessException('del操作失败', error);
    }
  }

  /**
   * 核销人员
   * 路由: GET verifier/type
   * PHP路由: Route::get('verifier/type', 'verify.Verifier/getVerifyType')
   */
  @Get('verifier/type')
  @ApiOperation({ summary: '核销人员' })
  async getVerifyType() {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getVerifyType
      // 直接返回字典数据
      return VerifyDict.getType();
    } catch (error) {
      throw new BusinessException('getVerifyType操作失败', error);
    }
  }
}
